package com.kolakcc.loljclient.model.swing;

import java.util.ArrayList;

import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

import com.kolakcc.loljclient.model.Region;

public class RegionsComboBoxModel implements ComboBoxModel<String> {
	protected ArrayList<Region> regionList;
	protected Region selectedRegion;

	public RegionsComboBoxModel() {
		// TODO: read regions from file, add all news urls
		this.regionList = new ArrayList<Region>();
		this.selectedRegion = new Region("EUROPE WEST", "EUW","http://euw.leagueoflegends.com/board/external.php?type=RSS2&forumids=3");
		this.regionList.add(this.selectedRegion);
		this.regionList.add(new Region("NORTH AMERICA", "NA","http://na.leagueoflegends.com/board/external.php?type=RSS2&forumids=9"));
		this.regionList.add(new Region("EUROPE NORDIC & EAST", "EUN","http://eune.leagueoflegends.com/board/external.php?type=RSS2&forumids=3"));
		this.regionList.add(new Region("KOREA", "KR"));
		this.regionList.add(new Region("BRAZIL", "BR"));
		this.regionList.add(new Region("TURKEY", "TR"));
		this.regionList.add(new Region("PUBLIC BETA ENVIRONMENT", "PBE"));
		this.regionList.add(new Region("SINGAPORE/MALAYSIA", "SG"));
		this.regionList.add(new Region("TAIWAN", "TW"));
		this.regionList.add(new Region("THAILAND", "TH"));
		this.regionList.add(new Region("PHILLIPINES", "PH"));
		this.regionList.add(new Region("VIETNAM", "VN"));

	}

	@Override
	public void addListDataListener(ListDataListener l) {
	}

	@Override
	public String getElementAt(int index) {
		return this.regionList.get(index).displayName;
	}

	@Override
	public Object getSelectedItem() {
		return this.selectedRegion.displayName;
	}

	public Region getSelectedRegion() {
		return this.selectedRegion;
	}

	@Override
	public int getSize() {
		return this.regionList.size();
	}

	@Override
	public void removeListDataListener(ListDataListener l) {
	}

	@Override
	public void setSelectedItem(Object anItem) {
		String search = (String) anItem;
		for (Region r : this.regionList) {
			if (r.displayName == search) {
				this.selectedRegion = r;
			}
		}
	}
}
